﻿Shader "Custom/NGUIMagicWave" 
{
	Properties 
	{
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_AlphaTex ("Alpha", 2D) = "white" {}
		_WaveTex ("WaveTex", 2D) = "white" {}
		_Amount ("Amout", Range(0.0, 1.0)) = 1.0
	}
	SubShader 
	{
		Tags 
		{ 
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType"="Transparent" 
		}

		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off
			Offset -1, -1
			ColorMask RGB
			AlphaTest Greater 0.01
			Blend SrcAlpha OneMinusSrcAlpha
			ColorMaterial AmbientAndDiffuse

			CGPROGRAM

			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			sampler2D	_MainTex;
			float4		_MainTex_ST;
			sampler2D	_AlphaTex;
			sampler2D	_WaveTex;
			half		_Amount;


			struct appdata_t
			{
				float4	vertex		:	POSITION;
				half4	color		:	COLOR;
				float2	texcoord	:	TEXCOORD0;
			};

			struct v2f
			{
				float4	vertex		:	POSITION;
				half4	color		:	COLOR;
				float2	texcoord	:	TEXCOORD0;
				float2	worldPos	:	TEXCOORD1;
			};

			v2f vert( appdata_t v )
			{
				v2f	o;
				o.vertex = mul( UNITY_MATRIX_MVP, v.vertex );
				o.color = v.color;
				o.texcoord = v.texcoord;
				o.worldPos = TRANSFORM_TEX( v.vertex.xy, _MainTex );
				return o;
			}

			half4 frag( v2f IN ) : COLOR
			{
				half4 col = tex2D( _MainTex, IN.texcoord ) * IN.color;		
				
				half2 alpha_uv = IN.texcoord;				
				//alpha_uv.y = alpha_uv.y + _Amount;
				alpha_uv.y = alpha_uv.y + ( 1.0 - _Amount );
				//alpha_uv.y = alpha_uv.y + 0.2;
				half4 a2 = tex2D( _AlphaTex, alpha_uv );										
				half4 wave = tex2D( _WaveTex, alpha_uv );				
				half4 wave_col = col;				
				wave_col *= wave.a;
				
				
				col.a *= a2.a;
				col += wave_col;
				
				return col;
			}
			ENDCG

		}
		
	} 
	
}
